{include template('header')}
{include template('top')}
<div id="uc">
{template uc/left}
<div id="uc_main">
	<div class="uc_tab">
	<ul>
		<li>{if !$action}<span class="on"><a href="{url home.php?f=notice}">公告列表</a></span>{else}<a href="{url('home.php?f=notice')}">公告列表</a>{/if}</li>
		<li>{if $action == 'add'}<span class="on">添加公告</span>{else}<a href="{url home.php?f=notice&a=add}">添加公告</a>{/if}</li>
		{if $action == 'edit'}<li><span class="on">编辑公告</span></li>{/if}
		<li>{if $action == 'draft'}<span class="on">草稿箱</span>{else}<a href="{url home.php?f=notice&a=draft}">草稿箱</a>{/if}</li>
		</ul>
	
	</div>
	<div id="uc_contain">
	{if $action == 'add' || $action == 'edit'}
			
			
	<form name="save" method="post" action="{url home.php?f=notice&a=save}" onsubmit="return check_write()">
	<input type="hidden" name="todraft" id="todraft" value="0" />
	<input type="hidden" name="aid" value="{$article['aid']}" />
		<table class="sub">
			<tr>
				<td width="60">标题：</td>
				<td><input type="text" name="title" class="input" size="54" value="{$article['title']}" onfocus="if(this.value=='未命名文章')this.value=''" /></td>
			</tr>
			<tr>
				<td>状态：</td>
				<td>
				<select name="status">
					<option value="0" {if $article['status'] == 0}selected="selected"{/if}>隐藏</option>
					<option value="1" {if $article['status'] == 1}selected="selected"{/if}>显示</option>
				</select>
				
				
				</td>
			</tr>

			</tbody>
			{if isset($attachments) && count($attachments)}
			<tr>
				<td>附件：</td>
				<td><input type="checkbox" name="show_attachments" value="1" onclick="$('#attachments').toggle()" id="show_attachments" class="checkbox" checked="checked" /><label for="show_attachments">显示该文章下的附件</label></td>
			</tr>
			<tbody id="attachments">
			<tr>
				<td></td>
				<td>
				<table width="98%" cellspacing="1">
					<tr>
						<th width="50">ID</th>
						<th>文件名</th>
						<th width="80">文件大小</th>
						<th width="120">上传时间</th>
						<th width="50">操作</th>
					</tr>
					{loop $attachments $attach}
					<tr id="tr_{$attach['fid']}" onmouseover="this.className='bg2'" onmouseout="this.className=''">
						<td width="50">{$attach['fid']}</td>
						<td>
						<?php
						if ( stristr($attach['filetype'], 'image') ) {
							$src = empty($attach['thumb']) ? $attach['filepath'] : $attach['thumb'];
							$preview ='<div class="preview" id="attach_'.$attach['fid'].'"><img src="'.$src.'" class="thumb" /></div>';
							$insert = '<img src=\'+\''.$attach['filepath'].'\'+\'></img>';
						} else {
							$preview = '';
							$insert = '[file]'.$src.'[/file]';
						}
						echo '[<a href="javascript:;" onclick="insert_attach(\'content\', \''.$insert.'\')">插入</a>] <a href="'.$insert.'" target="_blank" class="attach">'.$attach['originalname'].$preview.'</a>';
						?>
						</td>
						<td width="80">{echo sizecount($attach['filesize'])}</td>
						<td width="120">{echo gdate('Y-m-d H:i',$attach['dateline']);}</td>
						<td width="50"><a href="javascript:;" onclick="del_attach({$attach['fid']})">删除</a></td>
					</tr>
					{/loop}
				</table>
				</td>
			</tr>
			</tbody>
			{/if}
			<tr>
				<td valign="top">内容：</td><td>{echo editor('content','content',$article['content'].'','default','100%','250px',true)}</td>
			</tr>
			<tr>
			<td></td><td>
				<input type="submit" class="button" value="保存公告"  onclick="$('#todraft').val(0);"/>
				<input type="submit" class="button" value="存为草稿" onclick="$('#todraft').val(1);" />
			</td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">
	function useraddcates(){
		var name=$('#ucatename').val();
		var cstatus= $("input[name='cstatus']:checked").val();
		if(name.length<2){alert('分类名称不能少于两个字符');return false;}
		$.getJSON("home.php?f=category&a=save"+"&name="+encodeURIComponent(name)+"&cstatus="+cstatus+'&tm='+Math.random(),'',function(data){
			if(data.mstatus==true){
				var obj = document.getElementById("cid");
					obj.options.add(new Option(data.catename, data.cid));
					obj.options[obj.options.length-1].selected=true;
				$('#createcadiv').hide();
			}else{
				alert(data.msg);
				$('#ucatename').focus();
			}
			});

	}
				</script>
			
			
	{/if}
	
		{if !$action || $action == 'draft'}
		<table class="uc_table" >
				<tr>
				<th>ID</th><th style="width:340px;">{$lang['title']}</th><th  style="width:70px;">状态</th><th style="width:70px">添加时间</th>
				<th style="width:140px">{$lang['operation']}</th>
				</tr>
			{loop $articles $article}
			<tr id="tr{$article['aid']}">
			<td>{$article['aid']}</td>
			<td><div class="trtitle">{$article['title']}</div></td>
			<td>{if $article['status']>0}显示{else}隐藏{/if}</td>
			<td>{echo gdate('Y-m-d',$article['dateline'])}</td>
			
			{if $draft}
			<td><a href="{echo url("home.php?f=notice&a=edit&id=".$article['aid'])}" target="_blank" >[{$lang['change']}]</a> <a href="{echo url("home.php?f=notice&a=update&ajax=1&id=".$article['aid'])}" onclick="return updatearticle(this.href,'tr{$article['aid']}');" target="_blank">[{$lang['post']}]</a> <a href="{echo url("article.php?id=".$article['aid'])}" target="_blank">[{$lang['detail']}]</a></td>
			{else}
			<td><a href="{echo url("home.php?f=notice&a=edit&id=".$article['aid'])}" target="_blank" >[{$lang['change']}]</a> <a href="{echo url("home.php?f=notice&a=del&ajax=1&id=".$article['aid'])}" onclick="return deletearticle(this.href,'tr{$article['aid']}');" target="_blank">[{$lang['delete']}]</a> <a href="{echo url("article.php?id=".$article['aid'])}" target="_blank">[{$lang['detail']}]</a></td>
			{/if}
			</tr>
			{/loop}
			</table>
			{$pager}
			
			<script type="text/javascript">
			function deletearticle(u,id){
				if(confirm('{$lang["confirm_delete"]}')){
					$.getJSON(u+'&tm='+Math.random(),'',function(data){
						if(data.status==true){
							$('#'+id).hide();
						}else{
							alert(data.msg);
						}
						});
				}
				return false;
	
			}
			function updatearticle(u,id){
					$.getJSON(u+'&tm='+Math.random(),'',function(data){
						if(data.status==true){
							$('#'+id).hide();
						}else{
							alert(data.msg);
						}
						});
				return false;
	
			}
			</script>
	 {/if}
	
	 {if $action == 'cates'}
		<table class="uc_table" >
				<tr>
				<th>{$lang['category_name']}</th><th  style="width:70px;">{$lang['access']}</th><th>{$lang['article_total']}</th>
				<th style="width:140px">{$lang['operation']}</th>
				</tr>
			 {loop $categorys $category}
			<tr id="tr{$category['cid']}">
			<td>{$category['catename']}</td>
			<td>{$category_access[$category['status']]}</td>
			<td>{$category['total']}</td>
			<td><a href="{echo url("home.php?f=category&a=edit&id=".$category['cid'])}" target="_blank"  onclick="return changecategory(this.href);">[{$lang['change']}]</a> <a href="{echo url("home.php?f=category&a=del&ajax=1&id=".$category['cid'])}" onclick="return deletecategory(this.href,'tr{$category['cid']}');" target="_blank">[{$lang['delete']}]</a></td>
			</tr>
			 {/loop}
			</table>
			 {$pager}
			
			<script type="text/javascript">
			function changecategory(u,t){
				var edit = art.dialog({
				    title: '{$lang['change_category']}',
				    lock: true,
				    fixed: true, //C=G.DW
				    width:400,
				    height:200,
				    padding:'0 0 0 15px',
				    cssname:'uc_editfrind',
				    content: '<iframe src="'+u+'" frameborder="0" style="width:400px;height:200px;" />'
					});
				
				return false;
			}
			function catesadd(){
				var edit = art.dialog({
				    title: '{$lang['add_category']}',
				    lock: true,
				    fixed: true, //C=G.DW
				    content: '<p>分类名称：<input type="text" name="ucatename" id="ucatename" class="input"/></p>'+
							  '<p style="margin-top:6px;">浏览权限：<input type="radio" checked="checked" value="0" name="cstatus">完全开放'+
							  '<input type="radio" value="1" name="cstatus">仅好友可见'+
							 '<input type="radio" value="2" name="cstatus">仅自己可见'+
							 '</p><p style="margin-top:6px;"><input type="button" class="button" onclick="usercatesadd();" value="保存类别"/></p>'
					});
			}

			function usercatesadd(){
				var name=$('#ucatename').val();
				var cstatus= $("input[name='cstatus']:checked").val();
				if(name.length<2){alert('分类名称不能少于两个字符');return false;}
				$.getJSON("home.php?f=category&a=save"+"&name="+encodeURIComponent(name)+"&cstatus="+cstatus+'&tm='+Math.random(),'',function(data){
					if(data.mstatus==true){
						window.parent.location.reload();
					}else{
						alert(data.msg);
						$('#ucatename').focus();
					}
					});

			}

			function deletecategory(u,id){
				if(confirm('{$lang["confirm_delete"]}')){
					$.getJSON(u,'',function(data){
						if(data.status==true){
							$('#'+id).hide();
						}else{
							art.dialog({fixed: true,time: 2,content: data.msg});
						}
						});
				}
				return false;
			}
			</script>
	 {/if}

</div>
</div>
<div id="uc_right">

</div>
</div>
	{include template('footer')}